


struct Point {
    x: i32,
    y: i32,
}


fn foo() -> Point {
    let p = Point{x: 0, y: 2}; // Point 在栈上
    p
}

fn foo1() -> Box<Point> {
    let p = Point{x: 0, y: 2}; // Point 在栈上
    Box::new(p) // 将p实例按位复制了一份到堆上，p发生了move，p失效
}




fn foo2(){
    let mut p = 100;
    let bp = Box::new(p);
    p = 200;
    println!("p: {}", p); // 200
    println!("bp: {}", bp);  // 100

}




fn main() {

    let p = Point{x: 0, y: 2};
    let bp = Box::new(p);
    // let pp = *bp;
    println!("pp: {}", (*bp).x);

}